//
//  HomeBottomView.m
//  SHShopping
//
//  Created by 坤鼎 on 2019/8/26.
//  Copyright © 2019 kunding. All rights reserved.
//

#import "HomeBottomView.h"

@interface HomeBottomView ()

@property (nonatomic, strong) UIButton *btnLeft;
@property (nonatomic, strong) UIButton *btnRight0;
@property (nonatomic, strong) UIButton *btnRight1;
@property (nonatomic, strong) UIButton *btnRight2;

@property (nonatomic, strong) UILabel *btnLeftLb;
@property (nonatomic, strong) UILabel *btnLeftLbDetail;

@property (nonatomic, strong) UILabel *btnRight0Lb;
@property (nonatomic, strong) UILabel *btnRight1Lb;

@property (nonatomic, strong) UILabel *btnRight2Lb;
@property (nonatomic, strong) UILabel *btnRight2LbDetail;
@property (nonatomic, strong) NSMutableArray *arr;

@end

@implementation HomeBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
    UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(16, 24, SCREEN_WIDTH - 32, 31)];
    lb.text = @"遇见上海";
    lb.font = FONT_BOLD(22);
    [self addSubview:lb];
    
    CGFloat btnLeftWeight = (SCREEN_WIDTH - 32) * 143/343;
    CGFloat btnRight2Weight = (SCREEN_WIDTH - 32) * 190/343;
    CGFloat bage = (SCREEN_WIDTH - 32) * 10/343;
    CGFloat btnRight0Weight = (btnRight2Weight - bage) / 2;
    
    BaseButton *btnLeft = [[BaseButton alloc] initWithFrame:CGRectMake(16, GetViewYH(lb) + 16, btnLeftWeight, btnLeftWeight * 194/143)];
    btnLeft.tag = 10;
    self.btnLeft = btnLeft;
    [btnLeft addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnLeft];
    self.btnLeftLb = [[UILabel alloc] initWithFrame:CGRectMake(12, 137, btnLeft.frame.size.width - 24, 25)];
    self.btnLeftLbDetail = [[UILabel alloc] initWithFrame:CGRectMake(12, GetViewYH(self.btnLeftLb) + 4, btnLeft.frame.size.width - 24, 17)];
    self.btnLeftLb.font = FONT_BOLD(18);
    self.btnLeftLbDetail.font = FONT(12);
    self.btnLeftLb.textColor = [UIColor whiteColor];
    self.btnLeftLbDetail.textColor = [UIColor whiteColor];
    [btnLeft addSubview:self.btnLeftLb];
    [btnLeft addSubview:self.btnLeftLbDetail];
    
    BaseButton *btnRight0 = [[BaseButton alloc] initWithFrame:CGRectMake(GetViewXW(btnLeft) + 10, GetViewYH(lb) + 16, btnRight0Weight, btnRight0Weight)];
    btnRight0.tag = 11;
    self.btnRight0 = btnRight0;
    [btnRight0 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnRight0];
    self.btnRight0Lb = [[UILabel alloc] initWithFrame:CGRectMake(12, self.btnRight0.frame.size.height - 12 - 25, btnRight0.frame.size.width - 24, 25)];
    self.btnRight0Lb.font = FONT_BOLD(18);
    self.btnRight0Lb.textColor = [UIColor whiteColor];
    [btnRight0 addSubview:self.btnRight0Lb];
    
    BaseButton *btnRight1 = [[BaseButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 16 - btnRight0Weight, GetViewYH(lb) + 16, btnRight0Weight, btnRight0Weight)];
    btnRight1.tag = 12;
    self.btnRight1 = btnRight1;
    [btnRight1 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnRight1];
    self.btnRight1Lb = [[UILabel alloc] initWithFrame:CGRectMake(12, self.btnRight1.frame.size.height - 12 - 25, btnRight1.frame.size.width - 24, 25)];
    self.btnRight1Lb.font = FONT_BOLD(18);
    self.btnRight1Lb.textColor = [UIColor whiteColor];
    [btnRight1 addSubview:self.btnRight1Lb];
    
    BaseButton *btnRight2 = [[BaseButton alloc] initWithFrame:CGRectMake(GetViewX(btnRight0), GetViewYH(btnRight0) + 10, btnRight2Weight, btnRight2Weight * 94/190)];
    btnRight2.tag = 13;
    self.btnRight2 = btnRight2;
    [btnRight2 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnRight2];
    self.btnRight2Lb = [[UILabel alloc] initWithFrame:CGRectMake(12, 37, btnRight2.frame.size.width - 24, 25)];
    self.btnRight2LbDetail = [[UILabel alloc] initWithFrame:CGRectMake(12, GetViewYH(self.btnRight2Lb) + 4, btnRight2.frame.size.width - 24, 17)];
    self.btnRight2Lb.font = FONT_BOLD(18);
    self.btnRight2LbDetail.font = FONT(12);
    self.btnRight2Lb.textColor = [UIColor whiteColor];
    self.btnRight2LbDetail.textColor = [UIColor whiteColor];
    [btnRight2 addSubview:self.btnRight2Lb];
    [btnRight2 addSubview:self.btnRight2LbDetail];

    UILabel *lb2 = [[UILabel alloc] initWithFrame:CGRectMake(16, self.frame.size.height - 31, SCREEN_WIDTH - 32, 31)];
    lb2.text = @"购物攻略";
    lb2.font = FONT_BOLD(22);
    [self addSubview:lb2];
}

- (void)updateUIWith:(NSMutableArray *)arr {
    self.arr = arr;
    
    self.btnLeftLb.text = arr[0][@"title"];
    self.btnLeftLbDetail.text = arr[0][@"presentation"];

    self.btnRight0Lb.text = arr[1][@"title"];
    self.btnRight1Lb.text = arr[2][@"title"];
    
    self.btnRight2Lb.text = arr[3][@"title"];
    self.btnRight2LbDetail.text = arr[3][@"presentation"];
    
    [self.btnLeft sd_setImageWithURL:[NSURL URLWithString:arr[0][@"imgPath"]] forState:UIControlStateNormal placeholderImage:LHYPlaceholderImage];
    [self.btnRight0 sd_setImageWithURL:[NSURL URLWithString:arr[1][@"imgPath"]] forState:UIControlStateNormal placeholderImage:LHYPlaceholderImage];
    [self.btnRight1 sd_setImageWithURL:[NSURL URLWithString:arr[2][@"imgPath"]] forState:UIControlStateNormal placeholderImage:LHYPlaceholderImage];
    [self.btnRight2 sd_setImageWithURL:[NSURL URLWithString:arr[3][@"imgPath"]] forState:UIControlStateNormal placeholderImage:LHYPlaceholderImage];
}



- (void)btnAction:(UIButton *)btn {
    if (self.bottomBtnClickBlock) {    
        self.bottomBtnClickBlock(self.arr[btn.tag - 10][@"id"]);
    }
}


- (NSMutableArray *)arr {
    if (!_arr) {
        _arr = [[NSMutableArray alloc] init];
    }
    return _arr;
}

@end
